package com.woniu51.upload.controller;

import com.woniu51.upload.service.UploadService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;

/**
 * @author 杨光
 * @date 2022年03月30日 16:21
 */
@RestController
@CrossOrigin
public class FileUploadController {

    @Autowired
    UploadService uploadService;

    @RequestMapping("/upload")
    public String uploadFile(MultipartFile file, HttpServletRequest request){
        String authorization = request.getHeader("Authorization");
        System.out.println("Authorization=="+authorization);
        String fileName = uploadService.upload(file);
        return fileName;
    }
}
